package cn.elwy.rcp.ui.navigator.internal;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;

public class BuilderProjectFilter extends ViewerFilter {

  private static final String PROJECT_NATURE = "cn.elwy.rcp.builder.packer.ui.CNFProjectNature";

  public BuilderProjectFilter() {
  }

  @Override
  public boolean select(Viewer viewer, Object parentElement, Object element) {
    if (element instanceof IProject) {
      IProject project = (IProject) element;
      IProjectNature nature = null;
      try {
        nature = project.getNature(PROJECT_NATURE);
      } catch (CoreException e) {
      }
      if (nature != null) {
        return true;
      }
      return !project.isOpen();
    } else {
      return true;
    }
  }

}
